package com.godme.homework;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Gold2 {

    public static class Mountain{

        int needPeople;
        int value;

        public Mountain(int needPeople, int value){
            this.needPeople = needPeople;
            this.value = value;
        }

        public int getValue() {
            return value;
        }
    }

    public static int maxValue;

    public static void collect(List<Mountain> mountains, int people, int value){
        if(mountains.isEmpty() || people <= 0){
            recordValue(value);
            return;
        }
        int size = mountains.size();
        List<Mountain> temp;
        for (int i = 0; i < size; i++) {
            Mountain mountain = mountains.get(i);
            if(mountain.needPeople > people){
                recordValue(value);
                continue;
            }
            collect(mountains.stream().filter(e->!e.equals(mountain)).collect(Collectors.toList()), people - mountain.needPeople, value + mountain.value);
        }
    }

    public static void recordValue(int value){
        if(value > maxValue){
            maxValue = value;
        }
    }

    public static void main(String[] args) {
        collect(Arrays.asList(new Mountain(3, 3),
                new Mountain(4, 4),
                new Mountain(5, 5),
                new Mountain(6, 6)), 10, 0);
        System.err.println(maxValue);
    }
}
